#include <iostream>

using namespace std;

int main(){
    int val = 10;
    int *ptr = &val; //指向这个地址
    //ptr++;
    cout << *ptr << "\n"; //对指针进行解引用
    cout << ptr << "\n";  //输出地址
    *ptr++;
    cout << *ptr << "\n"; //对指针进行解引用
    cout << ptr << "\n";  //输出地址
    //直接使用指针进行管理
    int *ptr1 = new int;
    *ptr1 = 25;
     cout << *ptr1 << "\n";
    *ptr1 = 100;
    cout << *ptr1;
    cout << "\n";
    //不同数据类型
    char *ptr2 = new char; //注意数据类型一致
    *ptr2 = 'A';
    cout << *ptr2;
    cout << "\n";
    //使用指针进行数组操作
    int *arr = new int[5];
    for(int i = 0; i < 5; i++){
        arr[i] = i;
    }
    for(int i = 0; i < 5; i++){
        cout << arr[i] << " ";
    }
    cout << "\n";
    //用指针访问new出来的数组：
    int *ptr3 = arr;
    int cnt = 0;
    while(cnt < 10){
        cout << *ptr3 << " ";
        cnt++;  *ptr3++;
    }
    cout << "\n";
    //或者这样：
    ptr3 = arr; //记得复原
    for(int i = 0; i < 5; i++){
        cout << *(ptr3 + i) << " ";
    }
    cout << "\n";
    /*int* ppppp = nullptr;
    cout << *ppppp;*/
    return 0;
}